package com.xframe.xdal.core.model;

import lombok.Data;



/**
 * 功能描述:表示一个update set 子句
 *
 * @author xufeng
 * @version 1.0
 * @date 2022-09-26 SetWrapMode
 */
@Data
public class SetWrap implements IFieldToName{

    private SetWrapMode mode;

    private String fieldName;

    private Object val;

    @Override
    public String getFieldName() {
        return fieldName;
    }

    @Override
    public boolean isAttrPath() {
        return false;
    }

    @Override
    public boolean equals(Object anObject) {
        if (anObject instanceof SetWrap){
            SetWrap setWrap = (SetWrap)anObject;
            return this.fieldName.equals(setWrap.fieldName);
        }else {
            return false;
        }
    }

    @Override
    public int hashCode(){
        return this.fieldName.hashCode();
    }

    public SetWrap(String fieldName,Object val,SetWrapMode mode){
        this.fieldName = fieldName;
        this.val = val;
        this.mode = mode;
    }

    public SetWrap(String fieldName,Object val){
        this.fieldName = fieldName;
        this.val = val;
        this.mode = SetWrapMode.KEYVALUE;
    }

    public SetWrap(String fieldName){
        this.fieldName = fieldName;
        this.val = null;
        this.mode = SetWrapMode.KEYVALUE;
    }

}
